package cn.bellychang.ood.litejunit.v1.biz;

import cn.bellychang.ood.litejunit.v1.framework.TestCase;
import cn.bellychang.ood.litejunit.v1.framework.TestResult;
import cn.bellychang.ood.litejunit.v1.framework.TestSuite;

/**
 * @author ChangLiang
 * @date 2020/5/26
 */
public class CalculatorTest extends TestCase {


    public CalculatorTest(String name) {
        super(name);
    }

    Calculator calculator;

    @Override
    public void setUp() {
        calculator = new Calculator();
    }

    @Override
    public void tearDown() {
        calculator = null;
    }

    public void testAdd() {
        calculator.add(10);
        assertEquals(10,calculator.getResult());
    }

    public void testSubtract() {
        calculator.add(10);
        calculator.subtract(5);
        assertEquals(4,calculator.getResult());
    }

    public static void main(String[] args) {
        TestSuite testSuite = new TestSuite(CalculatorTest.class);

        // 这个TestResult不应该暴露给使用者
        TestResult testResult = new TestResult();
        testSuite.run(testResult);
        // 得到测试结果
        System.out.println(testResult.wasSuccessful());
        System.out.println("testcase count: " + testResult.runCount());
        System.out.println("failures count: " + testResult.getFailures().size());
        System.out.println("errors count: " + testResult.errorCount());
        testResult.getFailures().forEach(System.out::println);
    }
}
